﻿using DeepEarth.Map.TileSources;
using Microsoft.Maps.MapControl;
using Microsoft.Maps.MapControl.Core;
using System;

namespace DeepEarth.Map.BingMaps
{
    public class CustomMode : RoadMode
    {
        const int maxZoom = 21;

        public CustomMode(QuadKeyTileSourceProvider overlay)
        {
            var tileLayer = (MapTileLayer)Content;           
            tileLayer.TileSources.Clear();
            tileLayer.TileSources.Add(new CustomTileSource(overlay.PathFormat, Culture));
        }

        public override bool ConstrainView(Location center, ref double zoomLevel, ref double heading, ref double pitch)
        {
            if (zoomLevel < 1)
            {
                zoomLevel = 1;
                return true;
            }

            if (zoomLevel > maxZoom)
            {
                zoomLevel = maxZoom;
                return true;
            }

            return false;
        }


        // this appears to do nothing.
        public override Range<double> ZoomRange
        {
            get
            {
                return new Range<double>(1, maxZoom);
            }
        }
    }
}
